var api = require('../../util/api.js');
Page({
    data: {
        judgeName: "",
        action: "save"
    },
    onLoad: function (t) {
        api.chain({
            mode: 'EDIT'
        });
        this.setData({
            page: api.page(10),
            dataList: [],
            params: {
                subType: 2
            }
        });
        this.onReachBottom();
    },
    onPullDownRefresh() {
        this.setData({
          page: api.page(10),
          dataList: []
        });
        this.loadList();
      },
    onReachBottom() {
        this.loadList();
    },
    loadList() {
        var _this = this;
        var params = _this.data.params;
        var page = _this.data.page;
        api.get(api.url.examineList, params, page).then(res => {
            page.setTotal(res.total);
            if (res.rows.length == 0) {
                this.setData({
                    hasData: false
                })
            } else {
                _this.setData({
                    hasData: true,
                    dataList: _this.data.dataList.concat(res.rows)
                });
            }
        })
    },
    intoSystem: function (e) {
        // var examineId = e.currentTarget.dataset.id;
        // var examineName = e.currentTarget.dataset.name;
        var status = e.currentTarget.dataset.status;
        if (status == 0) {
            wx.showToast({
                title: '考核还未开始',
                icon: 'none'
            })
            return;
        }
        if (status == 2) {
            wx.showToast({
                title: '考核已经结束',
                icon: 'none'
            })
            return;
        }
        api.chain({
            examineId: e.currentTarget.dataset.id,
            examineName: e.currentTarget.dataset.name
        });
        wx.navigateTo({
            url: `../examine_item/item`
        })
    }
});